<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/common_setting_unit.php"); ?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--網站語言-->
    <meta http-equiv="Content-Language" content="zh-cn">
    <!--網站編碼-->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title><?php include '../coresection/title.php'; ?></title>
    <link rel="Shortcut Icon" href="../coresection/logoicon.ico">


</head>

<body style="display: none;">

<?
//设置需要搜索的表格的前缀后缀
global $table_Prefix;
$table_Suffix = "threed";
$table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

$nid = $_REQUEST['nid'];

$sql = "select img_order from ".$table." where detail_longnid = ".$nid;

$res = mysql_query($sql);

$list = array();

while($rows = mysql_fetch_assoc($res)){
	
	$list[] = $rows['img_order'];
	
}


$is_3d = false;
$is_images= false;
if(is_uploaded_file($_FILES['3d']['tmp_name'])){
	
	$threed_upfile = $_FILES["3d"];
	
	$threed_tmp_name = $threed_upfile["tmp_name"]; //上传文件的临时存放路径
	
	$threed_name = $nid.".3ds";
	
	move_uploaded_file($threed_tmp_name, '../../uploadfiles/' . $theme_folder . '/' . $threed_name);

	if(!in_array(0,$list)){
		$sql = "INSERT INTO $table (image,detail_longnid,img_order) value ('$threed_name','$nid','0')";
    	sql_log($sql);
$query = mysql_query($sql);
	}
}



for($i=0;$i<16;$i++){
    if(is_uploaded_file($_FILES['image'.$i.'']['tmp_name'])){

        $upfile = $_FILES["image".$i.""];

        $longnid = "D".$nid;
        $longname = $longnid."_".$i;

        $name = $longname.".png";

        $type = $upfile["type"]; //上传文件的类型
        $size = $upfile["size"]; //上传文件的大小
        $tmp_name = $upfile["tmp_name"]; //上传文件的临时存放路径
        /*
        这是一种非常简单文件上传方式。基于安全方面的考虑，您应当增加有关什么用户有权上传文件的限制。
        上传限制
        在这个脚本中，我们增加了对文件上传的限制。用户只能上传 .gif 或 .jpeg 文件
        */
        switch ($type) {
            case 'image/pjpeg':
                $okType = true;
                break;
            case 'image/jpeg':
                $okType = true;
                break;
            case 'image/gif':
                $okType = true;
                break;
            case 'image/png':
                $okType = true;
                break;
        }


        if ($okType) {
            /**
             * 0:文件上传成功<br/>
             * 1：超过了文件大小，在php.ini文件中设置<br/>
             * 2：超过了文件的大小MAX_FILE_SIZE选项指定的值<br/>
             * 3：文件只有部分被上传<br/>
             * 4：没有文件被上传<br/>
             * 5：上传文件大小为0
             */
            $error = $upfile["error"]; //上传后系统返回的值
            echo "================<br/>";
            echo "上传文件名称是：" . $name . "<br/>";
            echo "上传文件类型是：" . $type . "<br/>";
            echo "上传文件大小是：" . $size . "<br/>";
            echo "上传后系统返回的值是：" . $error . "<br/>";
            echo "上传文件的临时存放路径是：" . $tmp_name . "<br/>";

            echo "开始移动上传文件<br/>";
            //把上传的临时文件移动到up目录下面
            move_uploaded_file($tmp_name, '../../uploadfiles/' . $theme_folder . '/' . $name);
            $image = $name;
            echo "================<br/>";
            echo "上传信息：<br/>";
            if ($error == 0) {
                echo "文件上传成功啦！";
                echo "<br>图片预览:<br>";
                echo "<img src=" . $destination . ">";
                //echo " alt="图片预览:r文件名:".$destination."r上传时间:">";
            } elseif ($error == 1) {
                echo "超过了文件大小，在php.ini文件中设置";
            } elseif ($error == 2) {
                echo "超过了文件的大小MAX_FILE_SIZE选项指定的值";
            } elseif ($error == 3) {
                echo "文件只有部分被上传";
            } elseif ($error == 4) {
                echo "没有文件被上传";
            } else {
                echo "上传文件大小为0";
            }
        } else {
            echo "请上传jpg,gif,png等格式的图片！";
        }
		
		if(!in_array($i,$list)){
			$sql = "INSERT INTO $table (image,detail_longnid,img_order) value ('$image','$nid','$i')";
			sql_log($sql);
$query = mysql_query($sql);
		}
		else{
			 $sql = "update $table set image='$image' where (detail_longnid='$nid' and img_order='$i')";
        	sql_log($sql);
$query = mysql_query($sql) or die ('保存3D图失败！');
		}
       
        mysql_close($con);

    }

}



?>

<script type="text/javascript">
    alert("3D展示图片已保存，请点击返回！");
    document.location.href = "../detail/detail-list.php?sys_part=product";
</script>


</body>